home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel
/
CAROUSEL.cdr
/
mactosh
/
code
/
p_serlib.sit
/
Serial Library Source Code
/
serial.configure.dll.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-07-27
|
5KB
|
262 lines
/***********************************************************************/
/*
/* serial.configure.dll.c
/* by Atul Butte
/* Copyright ⌐ 1989 by Microsoft Corporation
/* All Rights Reserved
/*
/* version 1.0
/*
/*
/* This CALL/REGISTER will configure a serial port after it has been opened.
/*
/* Excel usage:
/*
/* = Register( "serial library", "serial.send", "IHHHHH" )
/* = Call( ref, portNumber, baud, stopbits, parity, data )
/*
/* where
/* portNumber = number of port (1 = modem, 2 = printer)
/* baud = baud rate
/* 1 = 300 baud
/* 2 = 600 baud
/* 3 = 1200 baud
/* 4 = 1800 baud
/* 5 = 2400 baud
/* 6 = 3600 baud
/* 7 = 4800 baud
/* 8 = 7200 baud
/* 9 = 9600 baud
/* 10 = 19200 baud
/* 11 = 57600 baud
/*
/* 300 = 300 baud
/* 600 = 600 baud
/* 1200 = 1200 baud
/* 1800 = 1800 baud
/* 2400 = 2400 baud
/* 3600 = 3600 baud
/* 4800 = 4800 baud
/* 7200 = 7200 baud
/* 9600 = 9600 baud
/* 19200 = 19200 baud
/* 57600 = 57600 baud
/* stopbits = number of stop bits
/* 1 = 1 stop bit
/* 2 = 1.5 stop bit
/* 3 = 2 stop bit
/*
/* 10 = 1 stop bit
/* 15 = 1.5 stop bit
/* 20 = 2 stop bit
/* parity = parity
/* 1 = no parity
/* 2 = even parity
/* 3 = odd parity
/* data = data bits
/* 1 = 5 data bits
/* 2 = 6 data bits
/* 3 = 7 data bits
/* 4 = 8 data bits
/*
/* 5 = 5 data bits
/* 6 = 6 data bits
/* 7 = 7 data bits
/* 8 = 8 data bits
/*
/***********************************************************************/
/***********************************************************************/
/*
/* D E F I N E S
/*
/***********************************************************************/
#define ROUTINE_NAME "serial.configure"
#define hNIL 0L
#define pNIL 0L
/***********************************************************************/
/*
/* I N C L U D E S
/*
/***********************************************************************/
#include "serial.h"
#include "error.h"
#include "get_port.h"
/***********************************************************************/
/*
/* main
/*
/***********************************************************************/
pascal short main( port, wBaud, wStopbits, wParity, wData )
unsigned short port; /* serial port to use */
unsigned short wBaud; /* baud rate */
unsigned short wStopbits; /* stop bits */
unsigned short wParity; /* parity */
unsigned short wData; /* data bits */
{
register OSErr err; /* result code from Toolbox routines */
register short config; /* configuration word */
short refIn; /* reference number for input port */
short refOut; /* reference number for output port */
SerShk flags;
RememberA0();
SetUpA4();
err = get_port( port, &refIn, &refOut );
if( err != noErr ) {
display_error( "Illegal port number." );
RestoreA4( );
return( err );
}
config = 0;
switch( wBaud ) {
case 1:
case 300:
config |= baud300;
break;
case 2:
case 600:
config |= baud600;
break;
case 3:
case 1200:
config |= baud1200;
break;
case 4:
case 1800:
config |= baud1800;
break;
case 5:
case 2400:
config |= baud2400;
break;
case 6:
case 3600:
config |= baud3600;
break;
case 7:
case 4800:
config |= baud4800;
break;
case 8:
case 7200:
config |= baud7200;
break;
case 9:
case 9600:
config |= baud9600;
break;
case 10:
case 19200:
config |= baud19200;
break;
case 11:
case 57600:
config |= baud57600;
break;
default:
display_error( "Improper baud rate setting." );
RestoreA4( );
return( errParam );
}
switch( wStopbits ) {
case 1:
case 10:
config |= stop10;
break;
case 2:
case 15:
config |= stop15;
break;
case 3:
case 20:
config |= stop20;
break;
default:
display_error( "Improper stop bit setting." );
RestoreA4( );
return( errParam );
}
switch( wParity ) {
case 1:
config |= noParity;
break;
case 2:
config |= evenParity;
break;
case 3:
config |= oddParity;
break;
default:
display_error( "Improper parity setting." );
RestoreA4( );
return( errParam );
}
switch( wData ) {
case 1:
case 5:
config |= data5;
break;
case 2:
case 6:
config |= data6;
break;
case 3:
case 7:
config |= data7;
break;
case 4:
case 8:
config |= data8;
break;
default:
display_error( "Improper data bit setting." );
RestoreA4( );
return( errParam );
}
err = SerReset( refOut, config );
if( err != noErr ) {
display_error( "Error in configuring output driver." );
RestoreA4( );
return( errSerialReset );
}
err = SerReset( refIn, config );
if( err != noErr ) {
display_error( "Error in configuring input driver." );
RestoreA4( );
return( errSerialReset );
}
flags.fXOn = 0;
flags.fCTS = 0;
flags.xOn = 0;
flags.xOff = 0;
flags.errs = parityErr | hwOverrunErr | framingErr;
flags.evts = 0;
flags.fInX = 0;
flags.fDTR = 0;
err = SerHShake( refOut, &flags );
if( err != noErr ) {
display_error( "Error in configuring output driver." );
RestoreA4( );
return( errSerialReset );
}
RestoreA4( );
return( noErr );
}
#include "get_port.c"